#!/bin/bash
menu(){
echo -e "\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
echo -e "\t\t\e[31m1.add user\e[0m"
echo -e "\t\t\e[31m2.delete user\e[0m"
echo -e "\t\t\e[31m3.query user information\e[0m"
echo -e "\t\t\e[31m4.reset user's password\e[0m"
echo -e "\t\t\e[31m5.modify user'sinformation\e[0m"
echo -e "\t\t\e[31m6.exit\e[0m"
echo -e "\t@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
read -p "请输入你的选择:" u_choice
}
modify(){
echo "1.修改uid"
echo "2.修改gid"
echo "3.修改shell"
echo "4.修改家目录"
read -p "选择修改内容:" mo_choice
case $mo_choice in
1)
	read -p "输入修改uid:" u_id
	usermod -u$u_id $mo_name
	;;
2)
	read -p "输入修改gid:" g_id
	usermod -g$g_id $mo_name
	;;
3)
	read -p "输入修改shell:" shell
	usermod -s$shell $mo_name
	;;
4)
	read -p "输入修改家目录:" home
	usermod -d$home $mo_name
	;;
esac
}
while :
do
	clear
	menu
	case $u_choice in
	1)
		read -p "输入要创建用户名:" add_name
		if id $add_name &>/dev/null
		then
		
			echo "用户已经存在"
		else
			useradd $add_name
			id $add_name
		fi
		read
		;;
	2)
		read -p "输入要删除用户名:" del_name
		if id $del_name &>/dev/null
		then
			read -p "确定要删除用户 $del_name 吗？[y/n]" ack
			if [ $ack == "y" ]
			then
				userdel -r $del_name&&echo "删除 $del_name 成功"
			fi
		else
			echo "用户 $del_name 不存在"
		fi
		read
		;;
	3)
		read -p "输入查询用户名:" qu_name
		if id $qu_name &>/dev/null
		then
			id $qu_name
		else
			echo "用户不存在"
		fi
		read
		;;
	4)
		read -p "输入设置用户名:" re_name
		read -p "输入设置密码:" re_passwd
		if id $re_name &>/dev/null
		then
			echo $re_passwd|passwd $re_name --stdin &>/dev/null
		else
			echo "用户不存在"
		fi
		read
		;;
	5)
		read -p "输入要修改用户名:" mo_name
		if id $mo_name &>/dev/null
		then
			modify
		else
			echo "用户不存在"
		fi
		read
		;;
	*)
		exit
		;;
	esac
		
done
